
from selenium import webdriver
import time
import urllib.request

driver = webdriver.Chrome()
driver.get('http://www.baidu.com')
driver.maximize_window()

driver.find_element_by_id('kw').send_keys('深圳')
driver.find_element_by_id('su').click()
time.sleep(2)
driver.find_element_by_link_text('图片').click()

first_img = driver.find_elements_by_css_selector('div.imgbox img[class="main_img img-hover"]')
i = 0
for item in first_img:
    url = item.get_attribute('data-imgurl')
    urllib.request.urlretrieve(url, str(i)+'pn.jpg')
    i += 1
    if i == 5:
        break
        
driver.quit()
